package com.cloud.controller;

import com.alibaba.fastjson.JSONObject;
import com.cloud.util.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.cloud.service.UserService;

@RestController
public class UserController {
	private static final Logger log = LoggerFactory.getLogger(UserController.class);
	@Autowired
	private UserService userService;
	
	@PostMapping("/user/list")
	public R list(@RequestBody JSONObject params) {
		params.put("isAdmin",false);
		return userService.queryAllUser(params);
	}

	@PostMapping("/admin/list")
	public R adminList(@RequestBody JSONObject params) {
		params.put("isAdmin",true);
		return userService.queryAllUser(params);
	}

	@PostMapping("/user/info")
	public R queryUser(@RequestBody JSONObject params) {
		params.put("isAdmin",false);
		return userService.queryUser(params);
	}

	@PostMapping("/admin/user")
	public R adminQueryUser(@RequestBody JSONObject params) {
		params.put("isAdmin",true);
		return userService.queryUser(params);
	}
	
	@RequestMapping("/admin/delete")
	public R delete(@RequestBody JSONObject params) {
		return userService.deleteUser(params);
	}

	@PostMapping("/user/update")
	public R update(@RequestBody JSONObject params) {
		params.put("isAdmin",false);
		return userService.updateUserInfo(params);
	}

	@PostMapping("/admin/update")
	public R adminUpdate(@RequestBody JSONObject params) {
		params.put("isAdmin",true);
		return userService.updateUserInfo(params);
	}
}
